package com.gjy.pulsar.simple;

import com.alibaba.fastjson.JSONObject;
import com.gjy.pulsar.disruptor.BGWorkGroupMixMarketBo;
import com.gjy.pulsar.disruptor.BGWorkMQMessageBo;
import com.gjy.pulsar.domain.NlMessage;
import com.gjy.pulsar.util.PulsarUtil;
import com.google.common.collect.Lists;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.Schema;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-08-02 10:09:57
 */
public class SimpleProduce {

    private static final String URL = "pulsar://192.168.253.142:6650/";

    public static void main(String[] args) throws PulsarClientException {
        PulsarClient client = PulsarClient.builder()
                .serviceUrl(PulsarUtil.URL)
                .build();

        // persistent://public/default/my-topic
        Producer<NlMessage> producer = client.newProducer(Schema.JSON(NlMessage.class)).topic("persistent://public/default/BG_GROUP_MIXMARKET_IN_11").create();
        NlMessage value = new NlMessage();
        value.setKey1("123212L");
        value.setOrgText(toJson());
        producer.newMessage().key("123212L").value(value).send();
        producer.close();
        client.close();
    }

    private static String toJson() {
        BGWorkMQMessageBo<BGWorkGroupMixMarketBo> b1 = new BGWorkMQMessageBo<>();
        b1.setKeyId(123212L);
        b1.setMessageType(2);
        b1.setWorkList(Lists.newArrayList(
                new BGWorkGroupMixMarketBo(1, 1, 1, 1),
                new BGWorkGroupMixMarketBo(2, 2, 2, 2)
        ));

        BGWorkMQMessageBo<BGWorkGroupMixMarketBo> b2 = new BGWorkMQMessageBo<>();
        b2.setKeyId(1232172L);
        b2.setMessageType(1);
        b2.setWorkList(Lists.newArrayList(
                new BGWorkGroupMixMarketBo(1, 1, 1, 1),
                new BGWorkGroupMixMarketBo(2, 2, 2, 2)
        ));

        return JSONObject.toJSONString(b1);
    }
}
